package com.ctn.information.util;

import java.util.HashMap;
import java.util.Map;

import com.ctn.information.content.SampleFragment;

import android.support.v4.app.Fragment;

/**
 * Fragment选择器
 * 
 * @author HLJ
 *
 */
public class SwitchFragmentUtil {

	static String[] topicFragments;

	public static Map<String, Fragment> map; 
	public static void bindTopocFragmentsIndex(String[] ary){
		topicFragments = ary;
	}
	
	public static void bindTopicFragment(String tag,Fragment fragment){
		if (map == null) {
			map = new HashMap<String, Fragment>();
		}
		map.put(tag, fragment);
	}
	
	public static Fragment getTopicFragment(String tag){
		return map.get(tag);
	}
	
	/**
	 * 直接创建Fragment
	 * 
	 * @param position
	 * @return
	 */
	public static Fragment newFragment(int position){
		Class clazz = null;
		try {
			clazz = Class.forName(topicFragments[position]);
			return (Fragment)clazz.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new SampleFragment();
	}
	
	/**
	 * 需要调用参数（未完成）
	 * 
	 * @param position
	 * @param objs
	 * @return
	 */
	public static Fragment getFragment(int position,Object[] objs){
		Class clazz = null;
		try {
			clazz = Class.forName(topicFragments[position]);
			return (Fragment)clazz.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new SampleFragment();
	}
	
}
